home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / ifp1s155.zip / IFPCOMON.PAS < prev    next >
Pascal/Delphi Source File  |  1992-04-21  |  12KB  |  616 lines

  1. unit ifpcomon;
  2.  
  3. interface
  4.  
  5. uses Crt, Dos, ifpglobl, ifpextrn;
  6.  
  7. function getkey2: char2;
  8. function getnum: word;
  9. procedure caption1(a: string);
  10. procedure caption2(a: string);
  11. procedure caption3(a : string);
  12. function nocarry(regs: registers) : boolean;
  13. function hex(a : word; b : byte) : string;
  14. procedure unknown(a: string; b: word; c: byte);
  15. procedure yesorno(a : boolean);
  16. procedure yesorno2(a: boolean);
  17. procedure dontknow;
  18. procedure dontknow2;
  19. procedure segofs(a, b : word);
  20. function showchar(a : char) : char;
  21. function power2(y: word): longint;
  22. procedure pause1;
  23. procedure pause2;
  24. procedure pause3(extra: integer);
  25. procedure pause4(direc: directions; var ch2: char2);
  26. procedure pause5(direc: directions; var ch2: char2);
  27. function bin4(a : byte) : string;
  28. procedure offoron(a : string; b : boolean);
  29. procedure zeropad(a : word);
  30. procedure showvers;
  31. function cbw(a, b : byte) : word;
  32. function bin16(a : word) : string;
  33. procedure drvname(a : byte);
  34. procedure media(a, b : byte);
  35. procedure pagenameclr;
  36. procedure Intr(intno: byte; var regs: registers);
  37. procedure MsDos(var regs: registers);
  38. procedure TextColor(color: byte);
  39. procedure TextBackground(color: byte);
  40. function unBCD(b: byte): byte;
  41. function addzero(b: byte): string;
  42. procedure modeinfo(var vidmode, vidlen, vidpg: byte; var vidwid: word);
  43. procedure box;
  44. procedure center(s: string);
  45. function EMSOK: boolean;
  46.  
  47. implementation
  48.  
  49. uses ifpscrpt, ifphelp;
  50.  
  51. function getkey2: char2;
  52.   var
  53.     c: char;
  54.     c2: char2;
  55.  
  56.   begin
  57.   c:=ReadKey;
  58.   if c = #0 then
  59.     getkey2:=c + ReadKey
  60.   else
  61.     getkey2:=c;
  62.   end; {getkey2}
  63.  
  64. {^Make sure number entered, not any letters}
  65. function getnum: word;
  66.   var
  67.     inpchar: char;
  68.     number_string: string[2];
  69.     temp, position, code: word;
  70.     row, col: byte;
  71.     finish: boolean;
  72.  
  73.   begin
  74.   row:=WhereY;
  75.   col:=WhereX;
  76.   Write(' ':3);
  77.   GotoXY(col, row);
  78.   temp:=99;
  79.   finish:=false;
  80.   position:=0;
  81.   number_string:='';
  82.   TextColor(LightGray);
  83.   repeat
  84.     inpchar:=ReadKey;
  85.     case inpchar of
  86.       '0'..'9':if position < 2 then
  87.         begin
  88.         Inc(position);
  89.         Inc(number_string[0]);
  90.         number_string[position]:=inpchar;
  91.         Write(inpchar)
  92.         end;
  93.       #8: if position > 0 then
  94.         begin
  95.         Dec(position);
  96.         Dec(number_string[0]);
  97.         Write(^H' '^H)
  98.         end;
  99.       #27: if number_string = '' then
  100.           finish:=true
  101.         else
  102.           begin
  103.           number_string:='';
  104.           GotoXY(col, row);
  105.           ClrEol;
  106.           position:=0
  107.           end;
  108.       #13: finish:=true
  109.     end {case}
  110.   until finish;
  111.   if number_string <> '' then
  112.     Val(number_string, temp, code)
  113.   else
  114.     temp:=999;
  115.   getnum:=temp
  116.   end; {getnum}
  117.  
  118. procedure caption1(a: string);
  119.   begin
  120.   textcolor(LightGray);
  121.   Write(a);
  122.   textcolor(LightCyan)
  123.   end; {caption1}
  124.  
  125. procedure caption2(a: string);
  126.   const
  127.     capterm = ': ';
  128.  
  129.   var
  130.     i: byte;
  131.     xbool: boolean;
  132.  
  133.   begin
  134.   i:=length(a);
  135.   while (i > 0) and (a[i] = ' ') do
  136.     dec(i);
  137.   insert(capterm, a, i + 1);
  138.   caption1(a)
  139.   end; {caption2}
  140.  
  141. procedure caption3(a : string);
  142.   begin
  143.   caption2('  ' + a)
  144.   end; {caption3}
  145.  
  146. function nocarry(regs: registers) : boolean;
  147.   begin
  148.   nocarry:=regs.flags and fcarry = $0000
  149.   end; {nocarry}
  150.  
  151. function hex(a : word; b : byte) : string;
  152.   const
  153.     digit : array[$0..$F] of char = '0123456789ABCDEF';
  154.  
  155.   var
  156.     i : byte;
  157.     xstring : string;
  158.  
  159.   begin
  160.   xstring:='';
  161.   for i:=1 to b do
  162.     begin
  163.     insert(digit[a and $000F], xstring, 1);
  164.     a:=a shr 4
  165.     end;
  166.   hex:=xstring
  167.   end; {hex}
  168.  
  169. procedure unknown(a: string; b: word; c: byte);
  170.   begin
  171.   Writeln('(unknown', ' ', a, ' ', hex(b, c), ')')
  172.   end; {unknown}
  173.  
  174. procedure yesorno(a : boolean);
  175.   begin
  176.   if a then
  177.     Writeln('yes')
  178.   else
  179.     Writeln('no')
  180.   end; {yesorno}
  181.  
  182. procedure yesorno2(a: boolean);
  183.   begin
  184.   if a then
  185.     Write('yes')
  186.   else
  187.     Write('no')
  188.   end; {yesorno2}
  189.  
  190. procedure dontknow;
  191.   begin
  192.   Writeln('(unknown)')
  193.   end; {dontknow}
  194.  
  195. procedure dontknow2;
  196.   begin
  197.   Write('(unknown)')
  198.   end; {dontknow2}
  199.  
  200. procedure segofs(a, b : word);
  201.   begin
  202.   Write(hex(a, 4), ':', hex(b, 4))
  203.   end; {segofs}
  204.  
  205. function showchar(a : char) : char;
  206.   begin
  207.   if a in pchar then
  208.     showchar:=a
  209.   else
  210.     showchar:='.'
  211.   end; {showchar}
  212.  
  213. function power2(y: word): longint;
  214.   begin
  215.   power2:=Trunc(exp((y * 1.0) * ln(2.0)))
  216.   end;
  217.  
  218. procedure pause1;
  219.   var
  220.     xbyte : byte;
  221.     xchar : char2;
  222.     SaveX, SaveY: byte;
  223.  
  224.   begin
  225.   xbyte:=TextAttr;
  226.   endit:=false;
  227.   TextColor(Cyan);
  228.   SaveX:=WhereX;
  229.   SaveY:=WhereY;
  230.   Write('( for more)');
  231.   if PrinterRec.Mode = 'A' then
  232.     ScreenPrint(Pg, PgNames[Pg], VerNum)
  233.   else
  234.     begin
  235.     repeat
  236.       xchar:=getkey2;
  237.       if xchar = #0#25 then
  238.         begin
  239.         ScreenPrint(Pg, PgNames[Pg], VerNum);
  240.         xchar:=#0#0
  241.         end;
  242.       if xchar = #0#$3B then
  243.         begin
  244.         HelpScreen(Pg, HelpVersion);
  245.         xchar:=#0#0
  246.         end;
  247.     until xchar <> #0#0;
  248.     if xchar <> #0#80 then
  249.       begin
  250.       endit:=true;
  251.       c2:=xchar
  252.       end;
  253.     end;
  254.   TextAttr:=xbyte;
  255.   GotoXY(SaveX, SaveY);
  256.   Write('            ')
  257.   end; {pause1}
  258.  
  259. procedure pause2;
  260.   var
  261.     xbyte : byte;
  262.  
  263.   begin
  264.   if WhereY + hi(WindMin) > hi(WindMax) then
  265.     begin
  266.     xbyte:=TextAttr;
  267.     TextColor(Cyan);
  268.     pause1;
  269.     if not endit then
  270.       begin
  271.       Clrscr;
  272.       Writeln('(continued)');
  273.       end;
  274.     TextAttr:=xbyte
  275.     end
  276.   end; {pause2}
  277.  
  278. procedure pause3(extra: integer);
  279.   var
  280.     xbyte: byte;
  281.   begin
  282.   endit:=false;
  283.   if WhereY + Hi(WindMin) + Abs(extra) > Hi(WindMax) then
  284.     begin
  285.     xbyte:=TextAttr;
  286.     TextColor(Cyan);
  287.     pause1;
  288.     if not endit then
  289.       begin
  290.       ClrScr;
  291.       if extra < 0 then
  292.         Writeln('(continued)');
  293.       end;
  294.     TextAttr:=xbyte
  295.     end
  296.   end; {pause3}
  297.  
  298. procedure pause4(Direc: Directions; var ch2: char2);
  299.   var
  300.     xbyte : byte;
  301.     xchar : char2;
  302.     SaveX, SaveY: byte;
  303.  
  304.   begin
  305.   xbyte:=TextAttr;
  306.   endit:=false;
  307.   TextColor(Cyan);
  308.   SaveX:=WhereX;
  309.   SaveY:=WhereY;
  310.   case Direc of
  311.     none:   Write('(any key)');
  312.     up:     Write('( for more)');
  313.     down:   Write('( for more)');
  314.     updown: Write('( or  for more)')
  315.   end;
  316.   repeat
  317.     if PrinterRec.Mode = 'A' then
  318.       if Direc = up then
  319.         xchar:=#0#81
  320.       else
  321.         begin
  322.         ScreenPrint(Pg, PgNames[Pg], VerNum);
  323.         xchar:=#0#80;
  324.         end
  325.     else
  326.       begin
  327.       xchar:=getkey2;
  328.       if xchar = #0#25 then
  329.         begin
  330.         ScreenPrint(Pg, Pgnames[Pg], VerNum);
  331.         xchar:=#0#0
  332.         end
  333.       end;
  334.   until xchar <> #0#0;
  335.   if (xchar[1] <> #0) or
  336.     ((xchar[1] = #0) and (not (xchar[2] in [#80, #72]))) then
  337.     begin
  338.     endit:=true;
  339.     c2:=xchar;
  340.     end;
  341.   TextAttr:=xbyte;
  342.   GotoXY(SaveX, SaveY);
  343.   Write('                 ');
  344.   ch2:=xchar;
  345.   end; {pause4}
  346.  
  347. procedure pause5(direc: directions; var ch2: char2);
  348.   var
  349.     xbyte : byte;
  350.  
  351.   begin
  352.   ch2:=#0#0;
  353.   if WhereY + Hi(WindMin) > Hi(WindMax) then
  354.     begin
  355.     xbyte:=TextAttr;
  356.     TextColor(Cyan);
  357.     Pause4(direc, ch2);
  358.     if not endit then
  359.       Clrscr;
  360.     TextAttr:=xbyte
  361.     end
  362.   end; {pause5}
  363.  
  364. function bin4(a : byte) : string;
  365.   const
  366.     digit : array[0..1] of char = '01';
  367.  
  368.   var
  369.     xstring : string;
  370.     i : byte;
  371.  
  372.   begin
  373.   xstring:='';
  374.   for i:=3 downto 0 do
  375.     begin
  376.     insert(digit[a mod 2], xstring, 1);
  377.     a:=a shr 1
  378.     end;
  379.   bin4:=xstring
  380.   end; {bin4}
  381.  
  382. procedure offoron(a : string; b : boolean);
  383.   begin
  384.   caption3(a);
  385.   if b then
  386.     Writeln('on')
  387.   else
  388.     Writeln('off')
  389.   end; {offoron}
  390.  
  391. procedure zeropad(a : word);
  392.   begin
  393.   if a < 10 then
  394.     Write('0');
  395.   Write(a)
  396.   end; {zeropad}
  397.  
  398. procedure showvers;
  399.   begin
  400.   if osmajor > 0 then
  401.     begin
  402.     Write(osmajor, decimal);
  403.     zeropad(osminor);
  404.     Writeln
  405.     end
  406.   else
  407.     Writeln('1', decimal, 'x')
  408.   end; {showvers}
  409.  
  410. function cbw(a, b : byte) : word;
  411.   begin
  412.   cbw:=word(b) shl 8 + a
  413.   end; {cbw}
  414.  
  415. function bin16(a : word) : string;
  416.   function bin8(a : byte) : string;
  417.     begin
  418.     bin8:=bin4(a shr 4) + '_' + bin4(a and $0F)
  419.     end; {bin8}
  420.  
  421.   begin {bin16}
  422.   bin16:=bin8(hi(a)) + '_' + bin8(lo(a))
  423.   end; {bin16}
  424.  
  425. procedure drvname(a : byte);
  426.   begin
  427.   Write(chr(ord('A') + a), ': ')
  428.   end; {drvname}
  429.  
  430. procedure media(a, b : byte);
  431.   procedure diskette(a, b, c : byte);
  432.     begin
  433.     Writeln('floppy ', a, ' side, ', b, ' sctr, ', c, ' trk')
  434.     end; {diskette}
  435.  
  436.   begin {media}
  437.   caption3('Media');
  438.   case a of
  439.     $FF : diskette(2, 8, 40);
  440.     $FE : diskette(1, 8, 40);
  441.     $FD : diskette(2, 9, 40);
  442.     $FC : diskette(1, 9, 40);
  443.     $F9 : if b = 1 then
  444.       diskette(2, 15, 80)
  445.     else
  446.       diskette(2, 9, 80);
  447.     $F8 : Writeln('fixed disk');
  448.     $F0 : diskette(2, 18, 80)
  449.     else
  450.       unknown('media', a, 2)
  451.   end
  452.   end; {media}
  453.  
  454. procedure pagenameclr;
  455.   var
  456.     xbyte: byte;
  457.  
  458.   begin
  459.   xbyte:=TextAttr;
  460.   Window(x1, tlength, x2 - 1, tlength);
  461.   TextColor((TextAttr and $70) shr 4);
  462.   ClrScr;
  463.   TextAttr:=xbyte;
  464.   Window(1, 1, twidth, tlength)
  465.   end; {pagenameclr}
  466.  
  467. procedure Intr(intno: byte; var regs: registers);
  468.   begin
  469.   AltIntr(intno, regs)
  470.   end;
  471.  
  472. procedure MsDos(var regs: registers);
  473.   begin
  474.   AltMsDos(regs)
  475.   end;
  476.  
  477. {These first two procedures filter the color commands to allow Black&White}
  478. procedure TextColor(color: byte);
  479.   var
  480.     temp: byte;
  481.   begin
  482.   if mono then
  483.     begin
  484.     case (color and $0F) of
  485.       0: temp:=0;
  486.       1..7: temp:=7;
  487.       8..15: temp:=15
  488.       end;
  489.     if color > 15 then
  490.       temp:=temp + Blink;
  491.     end
  492.   else
  493.     temp:=color;
  494.   Crt.TextColor(temp)
  495.   end; {TextColor}
  496.  
  497. procedure TextBackground(color: byte);
  498.   var
  499.     temp: byte;
  500.   begin
  501.   temp:=color;
  502.   if mono and (color < 7) then
  503.     temp:=0;
  504.   Crt.TextBackground(temp);
  505.   end; {TextBackground}
  506.  
  507. function unBCD(b: byte): byte;
  508.   begin
  509.   unBCD:=(b and $0F) + ((b shr 4) * 10)
  510.   end; {unBCD}
  511.  
  512. function addzero(b: byte): string;
  513.   var
  514.     c2: string[2];
  515.   begin
  516.   Str(b:0, c2);
  517.   if b < 10 then
  518.     c2:='0' + c2;
  519.   addzero:=c2
  520.   end; {addzero}
  521.  
  522. procedure modeinfo(var vidmode, vidlen, vidpg: byte; var vidwid: word);
  523.   var
  524.     regs: registers;
  525.  
  526.   begin
  527.   with regs do
  528.     begin
  529.     AH:=$0F;
  530.     Intr($10, regs);
  531.     vidmode:=AL;
  532.     vidwid:=AH;
  533.     vidpg:=BH;
  534.     AX:=$1200;
  535.     BL:=$10;
  536.     Intr($10, regs);
  537.     if BL = $10 then
  538.       vidlen:=25
  539.     else
  540.       vidlen:=Mem[$40:$84] + 1;
  541.     end
  542.   end; {modeinfo}
  543.  
  544. procedure box;
  545.   const
  546.     frame: array[1..8] of char = '╔═╗║║╚═╝';
  547.   var
  548.     h, w, x, y: word;
  549.  
  550.   begin
  551.   w:=Lo(WindMax) - Lo(WindMin) + 1;
  552.   h:=Hi(WindMax) - Hi(WindMin) + 1;
  553.   Inc(WindMax, $0101);
  554.   GotoXY(1, 1);
  555.   Write(frame[1]);
  556.   for x:=2 to w - 1 do
  557.     Write(frame[2]);
  558.   GotoXY(w, 1);
  559.   Write(frame[3]);
  560.   for y:=2 to h - 1 do
  561.     begin
  562.     GotoXY(1, y);
  563.     Write(frame[4]);
  564.     GotoXY(w, y);
  565.     Write(frame[5]);
  566.     end;
  567.   GotoXY(1, h);
  568.   Write(frame[6]);
  569.   GotoXY(2, h);
  570.   for x:=2 to w-1 do
  571.     Write(frame[7]);
  572.   GotoXY(w, h);
  573.   Write(frame[8]);
  574.   Dec(WindMax, $0202);
  575.   Inc(WindMin, $0101);
  576.   end;
  577.  
  578. procedure center(s: string);
  579.   var
  580.     x, halfwidth, halfstr: integer;
  581.  
  582.   begin
  583.   halfwidth:=(Lo(WindMax) - Lo(WindMin)) div 2;
  584.   halfstr:=Length(s) div 2;
  585.   if (halfwidth - halfstr) > 0 then
  586.     for x:=1 to (halfwidth - halfstr) do
  587.       Write(' ');
  588.   Write(s);
  589.   end;
  590.  
  591. function EMSOK: boolean;
  592.   var
  593.     S: string;
  594.     EMSSeg, Address: word;
  595.     Regs: Registers;
  596.  
  597.   begin
  598.   EMSOK:=false;
  599.   if longint(IntVec[$67]) <> 0 then
  600.     begin
  601.     EMSSeg:=longint(IntVec[$67]) shr 16;
  602.     S:='';
  603.     for Address:=$A to $11 do
  604.       S:=S + Chr(Mem[EMSSeg:Address]);
  605.     if S = 'EMMXXXX0' then
  606.       with Regs do
  607.         begin
  608.         AH:=$40;
  609.         Intr($67, regs);
  610.         if AH = 0 then
  611.           EMSOK:=true;
  612.         end;
  613.     end;
  614.   end;
  615.  
  616. end.